
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style>
        .xiaomi {
            width: 512px;
            height: 400px;
            border: 1px solid #f00;
            margin: 100px auto;
            overflow: hidden;
            position: relative;
        }
        .xiaomi span {
            position: absolute;
            left: 0;
            width: 100%;
            height: 200px;
            cursor: pointer;
        }
        .up {
            top: 0
        }
        .down {
            bottom: 0
        }
        #pic {
            position: absolute;
            top: 0;
            left: 0;
        }
    </style>
</head>
<body>
<div class="xiaomi">
    <img src="mi.png" alt="" id="pic"/>
    <span class="up" id="picUp"></span>
    <span class="down" id="picDown"></span>
</div>
</body>
</html>
<script>
    function $(id) { return document.getElementById(id);}
    var num = 0; // 控制图片的top值
    var timer = null; // 定时器名称
    $("picUp").onmouseover = function(){
        // alert(11);
        clearInterval(timer);
        timer =  setInterval(function(){
            num -= 3;
            num >= -1070 ? $("pic").style.top = num + "px" :  clearInterval(timer);

        },30);
    }
    $("picDown").onmouseover = function(){
        clearInterval(timer);
        timer  = setInterval(function(){
            num++;
            num < 0 ?  $("pic").style.top = num + "px" : clearInterval(timer);
        },30);
    }
    $("picUp").parentNode.onmouseout = function() {
        clearInterval(timer);
    }
</script>